package com.hgc.ch01.threadlocal;

/**
 * Created by 01367627 on 2019/6/15.
 */
public class ThreadLocalOOM {

    private static class LocalClass{
        private byte[] bytes = new byte[1024*1024*5];
    }

    private ThreadLocal<LocalClass> threadLocal = new ThreadLocal<LocalClass>();

    class MyRunnable implements Runnable{
        public void run() {
            threadLocal.set(new LocalClass());
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "=====================");
            //threadLocal.remove();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadLocalOOM threadLocalOOM = new ThreadLocalOOM();
        for(int i = 0;i<500;i++){
            new Thread(threadLocalOOM.new MyRunnable()).start();
        }
        Thread.sleep(1000*60*60L);
    }

}
